﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CShap_Enhancements
{
  class Program
  {
    static void Main(string[] args)
    {
      // var key word, Type inference
      var i = 10; // Type of i is Int32
      var s = "Hello world"; // type of s is String
      var d = 2.5; // type of d is Double
      Console.WriteLine("Type of {0} is {1}", i, i.GetType());
      Console.WriteLine("Type of {0} is {1}", s, s.GetType());
      Console.WriteLine("Type of {0} is {1}", d, d.GetType());

      var student = new Student();
      student.FirstName = "David";
      student.LastName = "Jame";
      Console.WriteLine("type of student is {0}", student.GetType());
      student.GetStudentName();
      //////////////////////////////////
      //Object initializer
      var st = new Student { FirstName = "Jone", LastName = "Tom" };
      var st2 = new Student { StudentID = "123456", FirstName = "Newton", LastName = "Abert" };
      st.GetStudentName();
      st2.GetStudentName();
      //Collection initializer
      int[] arrInt = new int[] { 1, 2, 3, 4, 5 };
      List<int> listOfInt = new List<int> { 1, 2, 3, 4, 5 };
      List<Student> listOfStudent = new List<Student>
      {
        new Student{FirstName="Tom", LastName="David"},
        new Student{StudentID="54321",LastName="Teo", FirstName="Le"},
        new Student()
      };
      listOfStudent[2].FirstName = "Nguyen";
      listOfStudent[2].LastName = "Duong";
      Console.WriteLine("List of Student:");
      foreach (var a in listOfStudent)
      {
        a.GetStudentName();
      }
      ////////////////////////////////
      //Anonymous Type
      ///////////////////////////////
      var obj = new { HoTen = "Nguyen Van Teo", Tuoi = 12, GioiTinh = true };
      var obj2 = new { HoTen = "Le Van Ti", Tuoi = 14, GioiTinh = true };
      var obj3 =new { HoTen = "Nguyen Van Teo", Tuoi = 12, GioiTinh = true };
      var obj4 = new { HoTen = "Tran Thi An", Tuoi = 14 };

      Console.WriteLine("{0} is type of {1}", obj, obj.GetType());
      Console.WriteLine("{0} get hash code: {1}", obj, obj.GetHashCode());
      Console.WriteLine("{0} is type of {1}", obj3, obj3.GetType());
      Console.WriteLine("{0} get hash code: {1}", obj3, obj3.GetHashCode());

      Console.WriteLine("obj equal obj3 is: {0}", obj.Equals(obj3));


      Console.WriteLine("{0} is type of {1}", obj2, obj2.GetType());
      Console.WriteLine("{0} get hash code: {1}", obj2, obj2.GetHashCode());
      
      Console.WriteLine("{0} is type of {1}", obj4, obj4.GetType());
      Console.WriteLine("{0} get hash code: {1}", obj4, obj4.GetHashCode());


      Console.ReadKey();
    }
  }
}
